program alg19;

{$APPTYPE CONSOLE}
{$Define log}


 var QsBC:array['a'..'z']of integer;

 procedure OUTPUT(T,p:string;ofset:integer);
   begin
     writeln(T);
     while ofset >1 do begin
                        write(' ');
                        dec(ofset);
                       end;
     writeln(p);
   end;

 procedure preQsBC(p:string);
     var m,j:integer;
         i:char;
   begin
     m := length(p);
     for i:='a' to 'z' do
       QsBC[i]:=m + 1;
     for j:=1 to m do
       QsBC[p[j]]:=m - j + 1;
   end;

 procedure QS(T,p:string);
     var n,m:integer;
         i,j:integer;
   begin
     (*
     prepocessing
     *)
     preQsBC(p);

     (*
     sheching
     *)
     n := length(T);
     m := length(p);

     i:=1;
     while (i <= n - m + 1) do
       begin
         j:=0;
         while (j < m)and(T[i+j] = p[j+1]) do inc(j);
         if j=m then
           begin
             {$IfDef log}
             writeln('== FIND OK ===========================================');
             {$Endif}
             OUTPUT(T,p,i);
             {$IfDef log}
             writeln('======================================================');
             {$Endif}
           end;
         (*
         shift
         *)

         // ==== Additional information ========
         {$IfDef log}
         OUTPUT(T,p,i);
         writeln('shift : = ',QsBC[T[i + m]]);
         {$Endif}
         // ====================================

         inc(i,QsBC[T[i + m]]);
       end;
   end;

begin
  //QS('ababbabba','bba');
  QS('gcatcgcagagagtatacagtacg','gcagagag');
  readln;
end.
